package com.anjho.pojo;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "genre")
@NamedQueries(value = {
		@NamedQuery(name = "Genre.getGenreList", query = "SELECT g FROM Genre g"),
		@NamedQuery(name = "Genre.getGenreByGecode", query = "SELECT g FROM Genre g WHERE g.gecode = :gecode")
})
public class Genre implements Serializable {

	private static final long serialVersionUID = -8665299164795806287L;
	
	@Id
	@Column(name="gecode")
	@OneToMany(mappedBy="genre")
	@GeneratedValue(strategy=GenerationType.SEQUENCE)
	private int gecode;
	
	@Column(name="description", nullable=false, length=50)
	private String description;
	
	public Genre() {
		this.gecode = 0;
		this.description = "";
	}

	public Genre(int gecode, String description) {
		this.gecode = gecode;
		this.description = description.toLowerCase();
	}

	public int getGecode() {
		return gecode;
	}

	public void setGecode(int gecode) {
		this.gecode = gecode;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description.toLowerCase();
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + gecode;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Genre other = (Genre) obj;
		if (gecode != other.gecode)
			return false;
		return true;
	}

}
